package com.nabi.starter.common.exception;


import cn.hutool.core.util.StrUtil;

/**
 * 数据校验
 */
public abstract class Assert {

    /**
     * 空字符效验
     *
     * @param str
     * @param message
     */
    public static void isBlank(String str, String message) {
        if (StrUtil.isBlank(str)) {
            throw new ApiException(ApiCode.PARAM_ERROR, message);
        }
    }

    /**
     * 空效验
     *
     * @param object
     * @param message
     */
    public static void isNull(Object object, String message) {
        if (object == null || object.toString().length() <= 0) {
            throw new ApiException(ApiCode.PARAM_ERROR, message);
        }
    }

    /**
     * 条件成立
     *
     * @param judge
     * @param message
     */
    public static void ifTrue(boolean judge, String message) {
        if (judge) {
            throw new ApiException(ApiCode.PARAM_ERROR, message);
        }
    }

    /**
     * 条件不成立
     *
     * @param judge
     * @param message
     */
    public static void ifFalse(boolean judge, String message) {
        if (!judge) {
            throw new ApiException(ApiCode.PARAM_ERROR, message);
        }
    }

    /**
     * 非空效验
     *
     * @param object
     * @param message
     */
    public static void isNotNull(Object object, String message) {
        if (!(object == null || object.toString().length() <= 0)) {
            throw new ApiException(ApiCode.PARAM_ERROR, message);
        }
    }


    /**
     * 长度效验
     *
     * @param object
     * @param leng
     * @param message
     */
    public static void isLengOut(Object object, int leng, String message) {
        isNull(object, message);
        if (object.toString().trim().length() > leng) {
            throw new ApiException(ApiCode.PARAM_ERROR, message);
        }
    }


}
